#!/usr/bin/ruby

def trim_microarray( in_f, out_f )
	in_file = File.open in_f
	out_file = File.open( out_f, 'w' )

	# Make the attributes to get, and write them as the header
	attributes = [:ProbeName, :GeneName, :SystematicName, :Description, :LogRatio]
	out_file.write( attributes.map{|att| att.to_s}.join("\t") )


	9.times {in_file.readline}

	# Get the header
	header = in_file.readline.strip.split "\t"
	indices = attributes.map {|att| header.index att.to_s}

	# Find the index of the control column
	control_index = header.index "ControlType"

	in_file.each_line do |l|
		new_l = l.strip.split "\t"
		if( new_l[control_index].to_i == 0 )
			elts = indices.map {|i| new_l[i]}
			out_file.write( "\n" + elts.join("\t") )
		end
	end

	in_file.close
	out_file.close
end

=begin
if(ARGV.length > 0)
	puts ARGV
	ARGV.each do |arg|
		split_name = arg.split( "." )
		trim_microarray( arg, split_name[0] + "_trim." + split_name[1])
	end
end
=end
